package org.dromara.patrol.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.patrol.domain.bo.PatrolSnapRecordBo;
import org.dromara.patrol.domain.vo.PatrolSnapRecordVo;
import org.dromara.patrol.service.IPatrolSnapRecordService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;


/**
 * 巡店管理-处理记录
 * 前端访问路由地址为:/system/snapRecord
 *
 * @author LionLi
 * @date 2024-03-27
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/snap/record")
public class PatrolSnapRecordController extends BaseController {

    private final IPatrolSnapRecordService patrolSnapRecordService;

    /**
     * 查询巡店管理-处理记录列表
     */
//    @SaCheckPermission("patrol:snapRecord:list")
    @GetMapping("/list")
    public TableDataInfo<PatrolSnapRecordVo> list(PatrolSnapRecordBo bo, PageQuery pageQuery) {
        return patrolSnapRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出巡店管理-处理记录列表
     */
    @SaCheckPermission("patrol:snapRecord:export")
    @Log(title = "巡店管理-处理记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PatrolSnapRecordBo bo, HttpServletResponse response) {
        List<PatrolSnapRecordVo> list = patrolSnapRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "巡店管理-处理记录", PatrolSnapRecordVo.class, response);
    }

    /**
     * 获取巡店管理-处理记录详细信息
     *
     * @param recordId 主键
     */
//    @SaCheckPermission("patrol:snapRecord:query")
    @GetMapping("/{recordId}")
    public R<PatrolSnapRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(patrolSnapRecordService.queryById(recordId));
    }

    /**
     * 新增巡店管理-处理记录
     */
    @SaCheckPermission("patrol:snapRecord:add")
    @Log(title = "巡店管理-处理记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PatrolSnapRecordBo bo) {
        return toAjax(patrolSnapRecordService.insertByBo(bo));
    }

    /**
     * 修改巡店管理-处理记录
     */
    @SaCheckPermission("patrol:snapRecord:edit")
    @Log(title = "巡店管理-处理记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PatrolSnapRecordBo bo) {
        return toAjax(patrolSnapRecordService.updateByBo(bo));
    }

    /**
     * 删除巡店管理-处理记录
     *
     * @param recordIds 主键串
     */
    @SaCheckPermission("patrol:snapRecord:remove")
    @Log(title = "巡店管理-处理记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(patrolSnapRecordService.deleteWithValidByIds(List.of(recordIds), true));
    }
}
